<?php
/**
 * category.inc.php
 */

if(!defined('IN_SITE') || !defined('IN_ADMIN')) {
	exit('Access Denied');
}

require_once SITE_ROOT.'include/cache.func.php';

$op = in_array($op, array('list', 'add', 'edit', 'editsave', 'del', 'setorder')) ? $op : 'list';

$cachefile = CACHE_PATH.'cache_category.php';
if(is_file($cachefile))
{
	@include $cachefile;
}
else
{
	updatecache('category');
	@include $cachefile;
}
$cate = $_SCACHE['category'];
	
if($op == 'list')
{
	$category = load("category.class.php");
	$cate = $category->getlist();
}
elseif ($op == 'add')
{
	if($cateaddsubmit)
	{
		$query = $db->query("INSERT INTO {$tablepre}category(fid, cname, type, path, displayorder) VALUES('$fid', '$cname', '$type', '$path', '$displayorder')");
		updatecache('category');
		if($query) showmessage("添加成功！", "?action=category&op=list");
	}
}
elseif ($op == 'edit')
{
	//取分类信息
	$category = $db->fetch_first("SELECT cid, fid, cname, type, path, displayorder FROM {$tablepre}category WHERE cid='$cid'");
}
elseif ($op == 'editsave')
{
	$query = $db->query("UPDATE {$tablepre}category SET fid='$fid', cname='$cname', type='$type', path='$path', displayorder='$displayorder' WHERE cid='$cid'");
	updatecache('category');
	if($query) showmessage("修改成功！", "?action=category&op=edit&cid=$cid");
}
elseif ($op == 'setorder')
{
	if($setordersubmit)
	{
		foreach ($cid as $key => $val) {
			$query = $db->query("UPDATE {$tablepre}category SET displayorder='$displayorder[$key]' WHERE cid='$val'");
		}
		updatecache('category');
		if($query) showmessage("排序完成！", "?action=category&op=list");
	}
}

include admin_tpl("category");
?>